//
//  AppDelegate.m
//  我的小汽车
//
//  Created by 杜远洋 on 14-12-31.
//  Copyright (c) 2014年 蓝欧科技. All rights reserved.
//

#import "AppDelegate.h"
#import "CarNewsViewController.h"
#import "ActivityViewController.h"
#import "MainViewController.h"
#import "CarTypeViewController.h"
#import "MineViewController.h"
#import <ShareSDK/ShareSDK.h>
#import "WeiboSDK.h"
@interface AppDelegate ()

@end

@implementation AppDelegate
- (void)dealloc
{
    
    [_window release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    [ShareSDK registerApp:@"4f5355fe776a"];
    [ShareSDK connect163WeiboWithAppKey:@"2076039637" appSecret:@"5d78216171da7182021b8d64bb8fa263" redirectUri:@"http://open.denglu.cc/receiver"];
    [ShareSDK connectSinaWeiboWithAppKey:@"2076039637" appSecret:@"5d78216171da7182021b8d64bb8fa263" redirectUri:@"http://open.denglu.cc/receiver" weiboSDKCls:[WeiboSDK class]];
    
    
    
    
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]]autorelease];
    [_window setBackgroundColor:[UIColor blackColor]];
    [_window makeKeyAndVisible];
    
    //tab
    UITabBarController *tab = [[UITabBarController alloc] init];
    tab.tabBar.barTintColor = [UIColor whiteColor];
    NSMutableArray *array = [NSMutableArray array];
    
    
    //资讯
    CarNewsViewController *carNews = [[CarNewsViewController alloc] init];
    UINavigationController *navCarNews = [[UINavigationController alloc] initWithRootViewController:carNews];
    navCarNews.navigationBar.translucent = NO;
    navCarNews.navigationBarHidden = NO;
    //135 206 255
    [navCarNews.navigationBar setBarTintColor:[UIColor colorWithRed:17/255.0f green:190/255.0f blue:227/255.0f alpha:1]];
    UIImage *newsImage = [UIImage imageNamed:@"iconfont-baozhixinwen.png"];
    UIImage *selectedNewsImage = [UIImage imageNamed:@"iconfont-baozhixinwen-2.png"];
    navCarNews.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"资讯" image:newsImage selectedImage:selectedNewsImage];
    [array addObject:navCarNews];
    
    
    //活动
    ActivityViewController *activity = [[ActivityViewController alloc] init];
    UINavigationController *navActivity = [[UINavigationController alloc] initWithRootViewController:activity];
    navActivity.navigationBar.translucent = NO;
    navActivity.navigationBarHidden = NO;
    [navActivity.navigationBar setBarTintColor:[UIColor colorWithRed:17/255.0f green:190/255.0f blue:227/255.0f alpha:1]];
    UIImage *activityImage = [UIImage imageNamed:@"iconfont-zuixinhuodong.png"];
    
    UIImage *selectedActivityImage = [UIImage imageNamed:@"iconfont-zuixinhuodong-2.png"];
    navActivity.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"活动" image:activityImage selectedImage:selectedActivityImage];
    [array addObject:navActivity];
    
    
    //首页
    MainViewController *main = [[MainViewController alloc] init];
    UINavigationController *navMain = [[UINavigationController alloc] initWithRootViewController:main];
    navMain.navigationBar.translucent = NO;
    navMain.navigationBarHidden = NO;
    [navMain.navigationBar setBarTintColor:[UIColor colorWithRed:17/255.0f green:190/255.0f blue:227/255.0f alpha:1]];
    UIImage *mainImage = [UIImage imageNamed:@"iconfont-home.png"];
    UIImage *selectedMainImage = [UIImage imageNamed:@"iconfont-home-2.png"];
    navMain.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"首页" image:mainImage selectedImage:selectedMainImage];
    [array addObject:navMain];
    
    
    //车型
    CarTypeViewController *carType = [[CarTypeViewController alloc] init];
    UINavigationController *navCarType = [[UINavigationController alloc] initWithRootViewController:carType];
    navCarType.navigationBar.translucent = NO;
    navCarType.navigationBarHidden = NO;
    [navCarType.navigationBar setBarTintColor:[UIColor colorWithRed:17/255.0f green:190/255.0f blue:227/255.0f alpha:1]];
    UIImage *carTypeImage = [UIImage imageNamed:@"iconfont-qichepeijian.png"];
    UIImage *selectedCarTypeImage = [UIImage imageNamed:@"iconfont-qichepeijian-2.png"];
    navCarType.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"车型" image:carTypeImage selectedImage:selectedCarTypeImage];
    [array addObject:navCarType];
    
    //我的
    MineViewController *mine = [[MineViewController alloc] init];
    UINavigationController *navMine = [[UINavigationController alloc] initWithRootViewController:mine];
    navMine.navigationBar.translucent = NO;
    navMine.navigationBarHidden = NO;
    [navMine.navigationBar setBarTintColor:[UIColor colorWithRed:17/255.0f green:190/255.0f blue:227/255.0f alpha:1]];
    UIImage *mineImage = [UIImage imageNamed:@"iconfont-wodelianmengicon.png"];
    UIImage *selectedMineImage = [UIImage imageNamed:@"iconfont-wodelianmengicon-2.png"];
    navMine.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我的" image:mineImage selectedImage:selectedMineImage];
    [array addObject:navMine];
    
    
    tab.viewControllers = array;
    
    [_window setRootViewController:tab];
    
    
    [tab release];
    [carNews release];
    [navMine release];
    [navMain release];
    [navCarType release];
    [navCarNews release];
    [navActivity release];
    [carType release];
    [activity release];
    [mine release];
    [main release];
    
    
    
    
    
    
    return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

- (BOOL)application:(UIApplication *)application
      handleOpenURL:(NSURL *)url
{
    return [ShareSDK handleOpenURL:url wxDelegate:self];
    
}

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation
{
    return [ShareSDK handleOpenURL:url
                 sourceApplication:sourceApplication
                        annotation:annotation
                        wxDelegate:self];
}


@end
